﻿
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;
#endregion

namespace SimplePong
{
    public class MainMenuScreen : Screen
    {
        //Fields
        List<IGraphicsControl> controls;
        String rootContent = "Textures/Menu/MainMenu/";
        
        Texture2D fondo;

        TextButton playButton;
        TextButton helpButton;
        TextButton aboutButton;

        SpriteFont menufont;
        SoundEffect clickSound;
        
        public MainMenuScreen()
            : base()
        {
            controls = new List<IGraphicsControl>();
        }

        public override void LoadContent()
        {
            
            fondo = GameGlobals.content.Load<Texture2D>(rootContent + "menu");
            menufont = GameGlobals.content.Load<SpriteFont>("Fonts/menu");


            playButton = new TextButton("Play", menufont, new Vector2(500, 100));
            playButton.Click += new EventHandler(play_Click);

            helpButton = new TextButton("Help", menufont, new Vector2(500, 200));
            helpButton.Click += new EventHandler(help_Click);

            aboutButton = new TextButton("About", menufont, new Vector2(500, 300));
            aboutButton.Click += new EventHandler(about_Click);


            clickSound = GameGlobals.content.Load<SoundEffect>("Sounds/c");

            //Add controls
            controls.Add(playButton);
            controls.Add(helpButton);
            controls.Add(aboutButton);       
        }

        
        public override void Initialize()
        {

        }

        public override void Update()
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                GameGlobals.isExiting = true;


            //Update all controls
            foreach (IGraphicsControl c in controls)
                c.Update();

            
        }

        public override void Draw()
        {
            spriteBatch.Begin();

            spriteBatch.Draw(fondo, Vector2.Zero, Color.White);

            //Draw all controls
            foreach (IGraphicsControl c in controls)
                c.Draw(spriteBatch);

            spriteBatch.End();
        }
  


        private void play_Click(object sender, EventArgs e)
        {
            clickSound.Play();
            ScreenManager.TransitionTo("Game", "BlackFade");
        }

        private void help_Click(object sender, EventArgs e)
        {
            clickSound.Play();
            ScreenManager.TransitionTo("Help", "BlackFade");
        }

        private void about_Click(object sender, EventArgs e)
        {
            clickSound.Play();
            ScreenManager.TransitionTo("About", "BlackFade");
        }
        
        

    }
}
